//
//  YKAppSetting.m
//  YK_CommonModule
//
//  Created by edward on 2021/6/21.
//

#import "YKAppSetting.h"

static NSString * const kOpen_product_environment = @"open_product_environment";

typedef id(^YKConfigBlock)(void);

@interface YKAppSetting ()

/// 是否是正式环境
@property (nonatomic, assign) BOOL isProduct;

@end

@implementation YKAppSetting


static YKAppSetting *_instance;

+ (id)allocWithZone:(struct _NSZone *)zone
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super allocWithZone:zone];
    });
    return _instance;
}

+ (instancetype)sharedInstance
{
    if (_instance == nil) {
        _instance = [[YKAppSetting alloc] init];
    }
    return _instance;
}

- (instancetype)init
{
    if(self = [super init]) {
        self.isProduct = [[NSUserDefaults standardUserDefaults] boolForKey:kOpen_product_environment];
    }
    return self;
}

- (nullable id)getConfigWithKey:(nonnull NSString *)key sandboxOperate:(id  _Nullable (^)(void))sandboxBlock productOperate:(id  _Nullable (^)(void))productBlock
{
    if (!self.isProduct && sandboxBlock && key) {
        
        
        return sandboxBlock();
    } else if (self.isProduct && productBlock && key) {
        
        
        return productBlock();
    }
    return nil;
}

- (void)forceUpdateProduct:(BOOL)isProduct
{
    self.isProduct = isProduct;
}



@end
